<template>
  <div class="show-main">
    <el-scrollbar style="height:100%">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <el-form :inline="true" :model="searchForm" ref="searchForm">
            <el-form-item prop="date">
              <el-date-picker v-model="date" type="datetimerange" align="right" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss"
                @change="(value) => {return dateChange(value,'searchForm')}">
              </el-date-picker>
            </el-form-item>
            <el-form-item prop="is_believe">
              <el-select v-model="searchForm.is_believe" clearable placeholder="请选择是否授信">
                <el-option label="非授信订单" value="0"></el-option>
                <el-option label="授信订单" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="draw_status">
              <el-select v-model="searchForm.draw_status" clearable placeholder="请选择划账状态">
                <el-option label="未划" value="0"></el-option>
                <el-option label="已划" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="status">
              <el-select v-model="searchForm.status" clearable placeholder="请选择订单状态">
                <el-option label="拒绝退款" value="-5"></el-option>
                <el-option label="取消订单" value="-4"></el-option>
                <el-option label="已退款" value="-3"></el-option>
                <el-option label="退货成功" value="-2"></el-option>
                <el-option label="申请退款" value="-1"></el-option>
                <el-option label="未出库" value="0"></el-option>
                <el-option label="出库待发货" value="1"></el-option>
                <el-option label="已发货" value="2"></el-option>
                <el-option label="已送达待收货" value="3"></el-option>
                <el-option label="已收货" value="4"></el-option>
                <el-option label="订单结束" value="5"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="search(true)">搜索</el-button>
              <el-button type="success" @click="search">刷新</el-button>
              <el-button type="warning" @click="draw('drawCompanyVisible')">支付通道划账</el-button>
              <el-button type="warning" @click="draw('drawAgentVisible')">代理商划账</el-button>
              <el-button type="warning" @click="draw('drawDriverVisible')">司机划账</el-button>
              <el-button type="warning" @click="draw('settlementVisible')">公司结算</el-button>
              <el-button type="danger" @click="drawLog">划账|结算记录</el-button>
            </el-form-item>
          </el-form>
        </div>
        <el-table :data="table" border>
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form v-if="props.row.status === -4" label-position="left" inline class="demo-table-expand">
                <el-form-item label="取消理由">
                  <span>{{ props.row.back_reason }}</span>
                </el-form-item>
              </el-form>
              <el-form v-if="props.row.status === -1" label-position="left" inline class="demo-table-expand">
                <el-form-item label="退款理由">
                  <span>{{ props.row.back_reason }}</span>
                </el-form-item>
                <el-form-item label="已退款金额">
                  <span>{{ props.row.back_money }}</span>
                </el-form-item>
                <el-form-item label="退款图片">
                  <el-image style="width: 100px; height: 100px" :src="props.row.back_image" :preview-src-list="[props.row.back_image]" :fit="fit">
                  </el-image>
                </el-form-item>
              </el-form>
              <el-form v-if="props.row.status === -3" label-position="left" inline class="demo-table-expand">
                <el-form-item label="退款理由">
                  <span>{{ props.row.back_reason }}</span>
                </el-form-item>
                <el-form-item label="退款金额">
                  <span>{{ props.row.back_money }}</span>
                </el-form-item>
                <el-form-item label="退款时间">
                  <span>{{ props.row.back_time|formatDate }}</span>
                </el-form-item>
                <el-form-item label="退款图片">
                  <el-image style="width: 100px; height: 100px" :src="props.row.back_image" :preview-src-list="[props.row.back_image]" :fit="fit">
                  </el-image>
                </el-form-item>
              </el-form>
              <el-form v-if="props.row.status === -5" label-position="left" inline class="demo-table-expand">
                <el-form-item label="退款理由">
                  <span>{{ props.row.back_reason }}</span>
                </el-form-item>
                <el-form-item label="退款图片">
                  <el-image style="width: 100px; height: 100px" :src="props.row.back_image" :preview-src-list="[props.row.back_image]" :fit="fit">
                  </el-image>
                </el-form-item>
                <el-form-item label="拒绝退款">
                  <span>{{ props.row.unback_reason }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="id" label="ID" width="70"></el-table-column>
          <el-table-column prop="role_type" label="下单类型">
            <template slot-scope="scope">
              <span v-if="scope.row.role_type === 1" style="color:#409EFF">老板下单</span>
              <span v-if="scope.row.role_type === 2" style="color:#67C23A">员工下单</span>
            </template>
          </el-table-column>
          <el-table-column prop="mastr_order_no" label="主订单号"></el-table-column>
          <el-table-column prop="order_no" label="订单号"></el-table-column>
          <el-table-column prop="total_price" label="订单总价"></el-table-column>
          <el-table-column prop="company_price" label="支付通道划账"></el-table-column>
          <el-table-column prop="company_status" label="支付通道划账状态">
            <template slot-scope="scope">
              <span v-if="scope.row.company_status === 0" style="color:#F56C6C">未划</span>
              <span v-if="scope.row.company_status === 1" style="color:#409EFF">已划</span>
            </template>
          </el-table-column>
          <el-table-column prop="primary_price" label="代理商划账"></el-table-column>
          <el-table-column prop="agent_status" label="代理商划账状态">
            <template slot-scope="scope">
              <span v-if="scope.row.agent_status === 0" style="color:#F56C6C">未划</span>
              <span v-if="scope.row.agent_status === 1" style="color:#409EFF">已划</span>
            </template>
          </el-table-column>
          <el-table-column prop="driver_price" label="司机划账"></el-table-column>
          <el-table-column prop="driver_status" label="司机划账状态">
            <template slot-scope="scope">
              <span v-if="scope.row.driver_status === 0" style="color:#F56C6C">未划</span>
              <span v-if="scope.row.driver_status === 1" style="color:#409EFF">已划</span>
            </template>
          </el-table-column>
          <el-table-column prop="is_believe" label="是否授信">
            <template slot-scope="scope">
              <span v-if="scope.row.is_believe === 1" style="color:#409EFF">授信</span>
              <span v-if="scope.row.is_believe === 0" style="color:#F56C6C">非授信</span>
            </template>
          </el-table-column>
          <el-table-column prop="beleive_status" label="授信结算">
            <template slot-scope="scope">
              <span v-if="scope.row.is_believe === 1 && scope.row.beleive_status === 0" style="color:#F56C6C">未结算</span>
              <span v-else-if="scope.row.is_believe === 1 && scope.row.beleive_status === 1" style="color:#F56C6C">已结算</span>
              <span v-if="scope.row.is_believe === 0">---</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="订单状态">
            <template slot-scope="scope">
              <span v-if="scope.row.status === -5">拒绝退款</span>
              <span v-if="scope.row.status === -4">取消订单</span>
              <span v-if="scope.row.status === -3">已退款</span>
              <span v-if="scope.row.status === -2">退货成功</span>
              <span v-if="scope.row.status === -1">申请退款</span>
              <span v-if="scope.row.status === 0">未出库</span>
              <span v-if="scope.row.status === 1">出库待发货</span>
              <span v-if="scope.row.status === 2">已发货</span>
              <span v-if="scope.row.status === 3">已送达待收货</span>
              <span v-if="scope.row.status === 4">已收货</span>
              <span v-if="scope.row.status === 5">订单结束</span>
            </template>
          </el-table-column>
          <el-table-column prop="is_pay" label="是否支付">
            <template slot-scope="scope">
              <span v-if="scope.row.is_pay === 0">未支付</span>
              <span v-if="scope.row.is_pay === 1">已支付</span>
            </template>
          </el-table-column>
          <el-table-column prop="is_pay" label="支付类型">
            <template slot-scope="scope">
              <span v-if="scope.row.is_pay === 1 && scope.row.pay_type == 0">微信支付</span>
              <span v-else-if="scope.row.is_pay === 1 && scope.row.pay_type == 1">余额支付</span>
              <span v-else-if="scope.row.is_pay === 1 && scope.row.pay_type == 2">授信支付</span>
              <span v-else style="color:#F56C6C">---</span>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="创建时间" width="150">
            <template slot-scope="scope">
              {{scope.row.create_time|formatDate}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="120">
            <template slot-scope="scope">
              <el-dropdown trigger="click" @command="handleCommand">
                <el-button type="primary">
                  操作菜单<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item :command="{cmd:'orderLog', id:scope.row.id}">订单日志</el-dropdown-item>
                  <el-dropdown-item v-if="scope.row.status === -1" :command="{cmd:'backMoney', row:scope.row}">受理退款</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
        <div class="page">
          <el-pagination @size-change="(val) =>{return handleSizeChange(val,'searchForm', 'search')}" @current-change="(val) =>{return handleCurrentChange(val,'searchForm', 'search')}" :current-page="searchForm.page"
            :page-sizes="[10,20,30,40]" :page-size="searchForm.limit" layout="total, sizes, prev, pager, next, jumper" :total="count">
          </el-pagination>
        </div>
      </el-card>
      <el-dialog title="订单日志" :visible.sync="orderLogVisible" :before-close="handleClose('orderLogTable')" width="1000px">
        <el-button type="success" @click="orderLogSearch">刷新</el-button>
        <el-table :data="orderLogTable" border>
          <el-table-column prop="name" label="操作人姓名" width="100"></el-table-column>
          <el-table-column prop="phone" label="操作人电话" width="100"></el-table-column>
          <el-table-column prop="role_type" label="操作人角色" width="100"></el-table-column>
          <el-table-column prop="change_message" label="操作内容"></el-table-column>
          <el-table-column prop="create_time" label="操作时间" width="140">
            <template slot-scope="scope">
              {{scope.row.create_time|formatDate}}
            </template>
          </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('orderLogVisible', 'orderLogTable')" size="small">关 闭</el-button>
        </span>
      </el-dialog>
      <el-dialog title="受理退款" :visible.sync="backMoneyVisible" :before-close="handleClose('backMoneyForm')" width="500px">
        <el-form ref="backMoneyForm" :model="backMoneyForm" label-width="100px" :rules="rules">
          <el-form-item label="状态" prop="status">
            <el-radio-group v-model="backMoneyForm.status">
              <el-radio :label="0" border>拒绝退款</el-radio>
              <el-radio :label="1" border>同意退款</el-radio>
            </el-radio-group>
          </el-form-item>
          <div v-if="backMoneyForm.status == 0">
            <el-form-item label="拒绝理由" prop="unback_reason">
              <el-input clearable v-model="backMoneyForm.unback_reason" placeholder="请输入拒绝理由"></el-input>
            </el-form-item>
          </div>
          <div v-else>
            <el-form-item label="订单金额" prop="total_price">
              <el-input disabled v-model="backMoneyForm.total_price"></el-input>
            </el-form-item>
            <el-form-item label="退款金额" prop="back_money">
              <el-input-number clearable v-model="backMoneyForm.back_money" placeholder="请输入拒绝理由" :precision="2" :step="0.1" :min="0.01" :max="backMoneyForm.total_price">
              </el-input-number>
            </el-form-item>
          </div>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('backMoneyVisible','backMoneyForm')" size="small">取 消</el-button>
          <el-button type="primary" @click="send('backMoneyVisible','backMoneyForm')" size="small">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog title="支付通道划账" :visible.sync="drawCompanyVisible" :before-close="handleClose('drawListTable')" width="500px">
        <el-table :data="drawListTable" border ref="drawListTable">
          <el-table-column prop="money" label="划账金额"></el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('drawCompanyVisible','drawListTable')" size="small">取 消</el-button>
          <el-button type="primary" @click="send('drawCompanyVisible','drawListTable')" size="small">划 账</el-button>
        </span>
      </el-dialog>
      <el-dialog title="代理商划账" :visible.sync="drawAgentVisible" :before-close="handleClose('drawListTable')" width="500px">
        <el-table :data="drawListTable" border ref="drawListTable">
          <el-table-column prop="money" label="划账金额"></el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('drawAgentVisible','drawListTable')" size="small">取 消</el-button>
          <el-button type="primary" @click="send('drawAgentVisible','drawListTable')" size="small">划 账</el-button>
        </span>
      </el-dialog>
      <el-dialog title="司机划账" :visible.sync="drawDriverVisible" :before-close="handleClose('drawListTable')" width="500px">
        <el-form :inline="true">
          <el-form-item>
            <el-input v-model="drawName" clearable placeholder="请输入司机名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="draw('drawDriverVisible')">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="drawListTable" border ref="drawListTable" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="driver_id" label="ID"></el-table-column>
          <el-table-column prop="name" label="司机名称"></el-table-column>
          <el-table-column prop="phone" label="司机电话"></el-table-column>
          <el-table-column prop="money" label="划账金额"></el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('drawDriverVisible','drawListTable')" size="small">取 消</el-button>
          <el-button type="primary" @click="send('drawDriverVisible','drawListTable')" size="small">划 账</el-button>
        </span>
      </el-dialog>
      <el-dialog title="公司结算" :visible.sync="settlementVisible" :before-close="handleClose('drawListTable')" width="500px">
        <el-form :inline="true">
          <el-form-item>
            <el-input v-model="drawName" clearable placeholder="请输入公司名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="draw('settlementVisible')">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="drawListTable" border ref="drawListTable" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column prop="group_id" label="ID"></el-table-column>
          <el-table-column prop="name" label="公司名称"></el-table-column>
          <el-table-column prop="money" label="结算金额"></el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('settlementVisible','drawListTable')" size="small">取 消</el-button>
          <el-button type="primary" @click="send('settlementVisible','drawListTable')" size="small">结 算</el-button>
        </span>
      </el-dialog>
      <el-dialog title="划账|结算记录" :visible.sync="logVisible" :before-close="handleClose('searchLogForm')" width="1000px">
        <el-form :inline="true" :model="searchLogForm" ref="searchLogForm">
          <el-form-item prop="type">
            <el-select v-model="searchLogForm.type" placeholder="请选择">
              <el-option label="支付通道划账" :value="1"></el-option>
              <el-option label="代理商划账" :value="2"></el-option>
              <el-option label="司机划账" :value="3"></el-option>
              <el-option label="公司结算" :value="4"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="name">
            <el-input v-model="searchLogForm.name" clearable placeholder="请输入名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchLog()">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="logTable" border ref="logTable">
          <el-table-column prop="id" label="ID" width="100"></el-table-column>
          <el-table-column prop="desc_name" label="操作对象" width="150"></el-table-column>
          <el-table-column prop="money" label="金额" width="100"></el-table-column>
          <el-table-column prop="draw_time" label="操作详情"></el-table-column>
          <el-table-column prop="create_time" label="操作时间">
            <template slot-scope="scope">
              {{scope.row.create_time|formatDate}}
            </template>
          </el-table-column>
        </el-table>
        <div class="page">
          <el-pagination @size-change="(val) =>{return handleSizeChange(val,'searchLogForm', 'searchLog')}" @current-change="(val) =>{return handleCurrentChange(val,'searchLogForm', 'searchLog')}"
            :current-page="searchLogForm.page" :page-sizes="[10,20,30,40]" :page-size="searchLogForm.limit" layout="total, sizes, prev, pager, next, jumper" :total="logCount">
          </el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="close('logVisible','searchLogForm')" size="small">取 消</el-button>
          <el-button type="primary" @click="send('logVisible','searchLogForm')" size="small">确定</el-button>
        </span>
      </el-dialog>
    </el-scrollbar>
  </div>
</template>
<script>
import { formatDateFun } from '@/untils/common.js'
import { getOrderList, getOrderLogList, backMoney, getDrawList, drawOrder, getDrawLogList } from '@/network/api.js'

export default {
  name: 'order',
  data() {
    return {
      date: [
        new Date(new Date(new Date().toLocaleDateString('zh')).getTime()),
        new Date(new Date(new Date().toLocaleDateString('zh')).getTime() + 24 * 60 * 60 * 1000 - 1)
      ],
      searchForm: {
        page: 1,
        limit: 10,
        start: formatDateFun(new Date(new Date().toLocaleDateString('zh')).getTime()),
        end: formatDateFun(new Date(new Date().toLocaleDateString('zh')).getTime() + 24 * 60 * 60 * 1000 - 1),
        is_believe: '',
        draw_status: '',
        status
      },
      table: [],
      count: 0,

      orderLogSearchForm: {
        id: 0
      },
      orderLogTable: [],
      orderLogVisible: false,

      backMoneyForm: {
        id: 0,
        status: 1,
        back_money: 0.01,
        unback_reason: '',
        total_price: 0
      },
      backMoneyVisible: false,

      drawName: '',
      multipleSelection: [],
      drawListTable: [],
      drawCompanyVisible: false, // 划账支付通道
      drawAgentVisible: false, // 划账代理商
      drawDriverVisible: false, // 划账司机
      settlementVisible: false, // 结算授信公司

      searchLogForm: {
        page: 1,
        limit: 10,
        type: 1,
        name: ''
      },
      logTable: [],
      logCount: 0,
      logVisible: false,

      rules: {
        status: [{ required: true, message: '状态必须', trigger: 'blur' }],
        unback_reason: [{ required: true, message: '理由必须', trigger: 'blur' }],
        back_money: [
          { required: true, message: '退款金额必须', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              if (value > this.backMoneyForm.total_price) {
                callback(new Error('退款金额不能大于订单总价格'))
              } else {
                callback()
              }
            },
            trigger: 'change'
          }
        ]
      }
    }
  },
  created() {
    this.search()
  },
  computed: {},
  methods: {
    // 每页条数变化
    handleSizeChange(val, formName, searchFunName) {
      this[formName].limit = val
      this[searchFunName]()
    },
    // 当前页变化
    handleCurrentChange(val, formName, searchFunName) {
      this[formName].page = val
      this[searchFunName]()
    },
    dateChange(v, formName) {
      if (v === null) {
        this[formName].start = ''
        this[formName].end = ''
      } else {
        this[formName].start = v[0]
        this[formName].end = v[1]
      }
    },
    async search(pageInit = false) {
      try {
        if (pageInit === true) {
          this.searchForm.page = 1
        }
        const rtn = await getOrderList(this.searchForm)
        this.table = rtn.list
        this.count = rtn.count
      } catch (e) {
        this.$message.error(e.message)
      }
    },
    async orderLogSearch() {
      try {
        const rtn = await getOrderLogList(this.orderLogSearchForm)
        this.orderLogTable = rtn
        this.orderLogVisible = true
      } catch (e) {
        this.$message.error(e.message)
      }
    },
    // 查看订单日志
    async orderLog(id) {
      this.orderLogSearchForm.id = id
      this.orderLogSearch()
    },
    // 受理退款
    backMoney(row) {
      this.backMoneyVisible = true
      this.$nextTick(() => {
        this.backMoneyForm.id = row.id
        this.backMoneyForm.total_price = row.total_price - 0
        this.backMoneyForm.unback_reason = ''
      })
    },
    // 划账列表
    async draw(visibleName) {
      if (this.date === null) {
        return this.$message.error('请先选择时间范围')
      }
      try {
        const rtn = await getDrawList({ start: this.searchForm.start, end: this.searchForm.end, draw_name: this.drawName, type: visibleName })
        this.drawListTable = rtn
        this[visibleName] = true
      } catch (e) {
        this.$message.error(e.message)
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 划账|结算记录
    drawLog() {
      this.searchLog()
    },
    async searchLog(pageInit = false) {
      try {
        if (pageInit === true) {
          this.searchLogForm.page = 1
        }
        const rtn = await getDrawLogList(this.searchLogForm)
        this.logTable = rtn.list
        this.logCount = rtn.count
        this.logVisible = true
      } catch (e) {
        this.$message.error(e.message)
      }
    },
    handleCommand(command) {
      switch (command.cmd) {
        case 'orderLog':
          this.orderLog(command.id)
          break
        case 'backMoney':
          this.backMoney(command.row)
          break
      }
    },
    // 关闭弹出前操作(不包括取消按钮)
    handleClose(formName) {
      return done => {
        switch (formName) {
          case 'drawSearchForm':
            this.drawSearchForm = { page: 1, limit: 10, date: '', start: '', end: '', name: '' }
            break
          case 'backMoneyForm':
            this.$refs[formName].clearValidate()
            this.$refs[formName].resetFields()
            break
          case 'drawListTable':
            this.drawName = ''
            this.multipleSelection = []
            break
          case 'searchLogForm':
            this.searchLogForm = { page: 1, limit: 10, type: 1, name: '' }
            break
        }
        done()
      }
    },
    // 取消按钮
    close(visibleName, formName) {
      switch (formName) {
        case 'drawSearchForm':
          this.drawSearchForm = { page: 1, limit: 10, date: '', start: '', end: '', name: '' }
          break
        case 'backMoneyForm':
          this.$refs[formName].clearValidate()
          this.$refs[formName].resetFields()
          break
        case 'drawListTable':
          this.drawName = ''
          this.multipleSelection = []
          break
        case 'searchLogForm':
          this.searchLogForm = { page: 1, limit: 10, type: 1, name: '' }
          break
      }
      this[visibleName] = false
    },
    async send(visibleName, formName) {
      if (formName === 'drawListTable') {
        const id = []
        switch (visibleName) {
          case 'drawCompanyVisible': // 支付通道划账
            try {
              await drawOrder({ id: '', type: visibleName, start: this.searchForm.start, end: this.searchForm.end })
              this.close(visibleName, formName)
              this.search()
            } catch (e) {
              this.$message.error(e.message)
            }
            break
          case 'drawAgentVisible': // 代理商划账
            try {
              await drawOrder({ id: '', type: visibleName, start: this.searchForm.start, end: this.searchForm.end })
              this.close(visibleName, formName)
              this.search()
            } catch (e) {
              this.$message.error(e.message)
            }
            break
          case 'drawDriverVisible': // 司机划账
            if (this.multipleSelection.length === 0) {
              return this.$message.error('请至少勾选一个')
            }
            this.multipleSelection.forEach(item => {
              id.push(item.driver_id)
            })
            try {
              await drawOrder({ id, type: visibleName, start: this.searchForm.start, end: this.searchForm.end })
              this.close(visibleName, formName)
              this.search()
            } catch (e) {
              this.$message.error(e.message)
            }
            break
          case 'settlementVisible': // 公司结算
            if (this.multipleSelection.length === 0) {
              return this.$message.error('请至少勾选一个')
            }
            this.multipleSelection.forEach(item => {
              id.push(item.group_id)
            })
            try {
              await drawOrder({ id, type: visibleName, start: this.searchForm.start, end: this.searchForm.end })
              this.close(visibleName, formName)
              this.search()
            } catch (e) {
              this.$message.error(e.message)
            }
            break
        }
      } else {
        this.$refs[formName].validate(async valid => {
          if (valid) {
            switch (formName) {
              case 'backMoneyForm': // 退款
                try {
                  await backMoney(this[formName])
                  this.close(visibleName, formName)
                  this.search()
                } catch (e) {
                  this.$message.error(e.message)
                }
                break
            }
          } else {
            this.$message.error('请检查表单')
            return false
          }
        })
      }
    }
  }
}
</script>
<style lang="less" scoped>
</style>
